package cn.pangza.web.utils;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import java.io.Serializable;

@Data
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class ResponseData<T> implements Serializable {

    private Integer code;

    private String message;

    private T data;

    public static<T> ResponseData<T> success() {
        ResponseData<T> tResponseData = new ResponseData<>();
        tResponseData.setCode(ResultCode.SUCCESS);
        tResponseData.setMessage("操作成功");
        return tResponseData;
    }

    public static<T> ResponseData<T> success(String message) {
        ResponseData<T> tResponseData = new ResponseData<>();
        tResponseData.setCode(ResultCode.SUCCESS);
        tResponseData.setMessage(message);
        return tResponseData;
    }

    public static<T> ResponseData<T> success(T data) {
        ResponseData<T> tResponseData = new ResponseData<>();
        tResponseData.setCode(ResultCode.SUCCESS);
        tResponseData.setData(data);
        tResponseData.setMessage("操作成功");
        return tResponseData;
    }

    public static <T> ResponseData<T> success(T data, String message) {
        ResponseData<T> tResponseData = new ResponseData<>();
        tResponseData.setCode(ResultCode.SUCCESS);
        tResponseData.setData(data);
        tResponseData.setMessage(message);
        return tResponseData;
    }

    public static <T> ResponseData<T> success(Integer code, T data, String message) {
        ResponseData<T> tResponseData = new ResponseData<>();
        tResponseData.setCode(code);
        tResponseData.setData(data);
        tResponseData.setMessage(message);
        return tResponseData;
    }

    public static<T> ResponseData<T> error() {
        ResponseData<T> tResponseData = new ResponseData<>();
        tResponseData.setCode(ResultCode.ERROR);
        tResponseData.setMessage("操作失败");
        return tResponseData;
    }

    public static<T> ResponseData<T> error(String message) {
        ResponseData<T> tResponseData = new ResponseData<>();
        tResponseData.setCode(ResultCode.ERROR);
        tResponseData.setMessage(message);
        return tResponseData;
    }
}
